package com.axx.android.base;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.axx.android.LetterApp;
import com.axx.android.common.Constants;
import com.axx.android.profile.auth.activity.LoginActivity;
import com.axx.android.utils.ToastUtils;

import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/7/21 0021.
 */

public abstract class BaseFragment extends Fragment implements BaseView {

    public abstract int getLayoutId();
    public abstract  void init(Bundle savedInstanceState);
    private String title;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public void showToast(String msg) {
        ToastUtils.showShortToast(getContext(), msg);
    }

    @Override
    public void showLoading(String msg) {

    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(getLayoutId(),container,false);
        ButterKnife.bind(this,view);
        init(savedInstanceState);
        return view;
    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void showErrorParse() {
        showToast(Constants.ERROR_PARSE);
    }

    @Override
    public void showErrorNet() {
        showToast(Constants.ERROR_NET);
    }


    public void startCheckAuth(Class clazz) {
        if (LetterApp.authUser == null) {
            startActivity(new Intent(getContext(), LoginActivity.class));
        } else {
            startActivity(new Intent(getContext(), clazz));
        }
    }
}
